package edu.uclmgmu.bacteriosec.aspects.java.io.PrintStream;

import edu.uclmgmu.bacteriosec.aspects.common.Store;

public aspect PrintStream_RemoveFirstByte {
	void around(java.io.PrintStream caller, String a) : call(void java.io.PrintStream.print(String)) && 
			target(caller) && args(a) &&
			!cflow(within(PrintStream_CountCalls)) && !within(edu.uclmgmu.bacteriosec.aspects.common.Store) 
			&& !within(junit.*) {
		String currentJoinPoint = Store.getCurrentjoinPoint();
		String signature=thisJoinPointStaticPart.getSignature().toString();
		if (currentJoinPoint.equals(signature)) {
			int numberOfCallInTurn = Store.getNumberOfCallInTurn(signature);
			int numberOfCurrentCall = Store.getNumberOfCurrentCall(signature);
			if (numberOfCallInTurn == numberOfCurrentCall) {
				Store.updateNumberOfCurrentCall(signature);
				proceed(caller, a.substring(1));
			} else {
				Store.updateNumberOfCurrentCall(signature);
				proceed(caller, a);
			}
		} else {
			Store.updateNumberOfCurrentCall(signature);
			proceed(caller, a);
		}
	}

	void around(java.io.PrintStream caller, String a) : call(void java.io.PrintStream.println(String)) && 
			target(caller) && args(a) &&
			!cflow(within(PrintStream_CountCalls)) && !within(edu.uclmgmu.bacteriosec.aspects.common.Store) 
			&& !within(junit.*) {
		String currentJoinPoint = Store.getCurrentjoinPoint();
		String signature=thisJoinPointStaticPart.getSignature().toString();
		if (currentJoinPoint.equals(signature)) {
			int numberOfCallInTurn = Store.getNumberOfCallInTurn(signature);
			int numberOfCurrentCall = Store.getNumberOfCurrentCall(signature);
			if (numberOfCallInTurn == numberOfCurrentCall) {
				Store.updateNumberOfCurrentCall(signature);
				proceed(caller, a.substring(1));
			} else {
				Store.updateNumberOfCurrentCall(signature);
				proceed(caller, a);
			}
		} else {
			Store.updateNumberOfCurrentCall(signature);
			proceed(caller, a);
		}
	}
}
